package com.slimbloody.ReflectTest;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.reflection.Reflector;

import java.lang.reflect.*;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReflectTest {
  private Integer a;
  private List<String> bList;
  private Boolean c;

  public ReflectTest(String str) {
    this.a = Integer.parseInt(str);
  }

  public Integer add(Integer b) {
    return a + b;
  }

  public static void main(String[] args) {
    ReflectTest reflectTest = new ReflectTest();
    Constructor<?>[] declaredConstructors = reflectTest.getClass().getDeclaredConstructors();
    Constructor<?>[] constructors = reflectTest.getClass().getConstructors();

    try {
      Method add = reflectTest.getClass().getMethod("add", Integer.class);
      String name = add.getName();
      Class<?> returnType = add.getReturnType();
      AnnotatedType annotatedReturnType = add.getAnnotatedReturnType();
      Class<?>[] parameterTypes = add.getParameterTypes();

      Field fieldA = reflectTest.getClass().getDeclaredField("a");

      Type genericType = fieldA.getGenericType();
      Class<?> type = fieldA.getType();


      Field fieldB = reflectTest.getClass().getDeclaredField("bList");
      Class<?> type1 = fieldB.getType();
      // 泛型: Ljava/util/List<Ljava/lang/String;>;
      Type genericType1 = fieldB.getGenericType();

      System.out.println();
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(e);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    }
    /*
    TypeVariable：表示泛型类型参数，如 T。
    ParameterizedType：表示具体的泛型类型，如 List<String>。
    GenericArrayType：表示泛型数组类型，如 T[]
     */
    Reflector reflector = new Reflector(ReflectTest.class);
  }
}
